package com.amos.muexamcore.core;

import com.amos.bean.Result;
import com.amos.core.BaseDTO;
import com.amos.core.BaseService;
import org.springframework.web.bind.annotation.*;

/**
 * Copyright © 2018 五月工作室. All rights reserved.
 *
 * @Package com.amos.muexamcore.core
 * @ClassName BaseController
 * @Description 通用方法基类
 * @Author Amos
 * @Modifier
 * @Date 2020/3/8 23:14
 * @Version 1.0
 **/
public abstract class BaseController<T extends BaseDTO> {

    public abstract BaseService getService();

    /**
     * 根据id加载
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result load(@PathVariable("id") String id) {
        return Result.success(getService().load(id));
    }

    /**
     * 根据id删除
     *
     * @param id
     * @return
     */
    @DeleteMapping("{id}")
    public Result delete(@PathVariable("id") String id) {
        return Result.success(getService().logicDeleted(id));
    }

    /**
     * 条件查询
     *
     * @param dto
     * @return
     */
    @PostMapping("/select")
    public Result select(@RequestBody T dto) {
        return Result.success(getService().select(dto));
    }

    /**
     * 保存
     *
     * @param dto
     * @return
     */
    @PostMapping("/save")
    public Result save(@RequestBody T dto) {
        return Result.success(getService().save(dto));
    }
}
